/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Map;

import IO.Utils;
import IO.models.MapsConfig;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author insane
 */
public class MapLevel {

    private static MapLevel instance = new MapLevel();
    private int level = 0;
    private int maxLevel = 15;
    private ArrayList<Map> levelMap;
    private Map map;

    private MapLevel() {
        init();
    }

    private void init() {
        levelMap = new ArrayList();
        for (int i = 0; i < maxLevel; i++) {
            levelMap.add(null);
        }
    }

    public static MapLevel getInstance() {
        return instance;
    }

    private Map mapList(int l) throws FileNotFoundException, IOException, ClassNotFoundException {
        //time check
        Utils ut = new Utils();
        //time check

        //time check
        ut.timeCheck("start createMap()");
        //time check
        ArrayList maps = MapsConfig.getInstance().getMap();

        map = (Map) maps.get(level);

        if (map.getMap() == null) {

            map.createMap();
            //time check
            ut.timeCheck("end createMap()");
            //time check

        }

        return map;
    }

    public Map getMap() throws FileNotFoundException, IOException, ClassNotFoundException {

        if (levelMap.get(level) == null) {
            levelMap.set(level, mapList(level));
        }
        return (Map) levelMap.get(level);
    }

    /**
     * @return the level
     */
    public int getLevel() {
        return level;
    }

    /**
     * @param level the level to set
     */
    public void setLevel(int level) {
        this.level = level;
    }

    public int getCountLevel() {
        return levelMap.size();
    }
}
